package com.android.websms;

import android.content.Context;
import android.database.Cursor;
import android.net.UrlQuerySanitizer;

import com.android.webserver.fwapi.HTMLPage;
import com.android.webserver.fwapi.Request;

public class Messages extends HTMLPage
{

	public Messages(Context context, Request request)
	{
		super(context, request);
	}

	
	@Override
	protected boolean create(Object... objects)
	{
		String text = getPOSTParameter("text", UrlQuerySanitizer.getAllButNulLegal());
		DBPenTest db = new DBPenTest(context);
		
		appendHTMLContent(context.getString(R.string.Header),
				new String[] { "Messages" });
		if (text != null)
		{
			appendStaticHTMLContent("<a href=\"message\">back</a>");
			
			db.addMessage(text);
		}
		else
		{
		appendStaticHTMLContent("<ul>");
		Cursor c = db.getMessages();
		for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
			appendStaticHTMLContent("<li>"+ c.getString(0)+"</li>");
		appendStaticHTMLContent("</ul><br/><form method=\"POST\" action=\"\"><input type=\"text\" name=\"text\"/> </form>");
		}
	appendStaticHTMLContent(context.getString(R.string.Footer));
	return true;
	}
}
